package com.dididoctor.patient.Activity.Usercentre.Record.Cases;

import android.content.Context;

import com.dididoctor.patient.Activity.ConstantValue;
import com.dididoctor.patient.Bean.Token;
import com.dididoctor.patient.Http.MyHttpResponseHandler;
import com.dididoctor.patient.MV.BasePresenter;
import com.dididoctor.patient.MV.BusinessClient;
import com.dididoctor.patient.MV.Response;
import com.dididoctor.patient.Utils.Util;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/4/15.
 */
public class CasesPresenter extends BasePresenter {

    private CasesView view;

    public CasesPresenter(Context context, CasesView view) {
        super(context, view);
        this.view = view;
    }

    public void getCases(int pageIndex) {
        RequestParams params = new RequestParams();
        params.put("userId", Token.getId());
        params.put("token", Token.getToken());
        params.put("pageIndex", Util.toString(pageIndex));
        params.put("pageSize", "10");
        BusinessClient.post(ConstantValue.medicalist, params, new MyHttpResponseHandler() {

            private List<CasesBean> casesBeans = new ArrayList<CasesBean>();
            private List<Map<String, String>> maps = new ArrayList<Map<String, String>>();

            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    maps = response.getListData("medicalist");
                    for (Map<String, String> map : maps) {
                        CasesBean casesBean = new CasesBean();
                        casesBean.setRecId(Util.toString(map.get("recId")));
                        casesBean.setHosName(Util.toString(map.get("hosName")));
                        casesBean.setClinicDate(Util.toString(map.get("clinicDate")));
                        casesBean.setDctName(Util.toString(map.get("dctName")));
                        casesBean.setDescr(Util.toString(map.get("descr")));
                        casesBean.setType(Util.toString(map.get("type")));
                        casesBeans.add(casesBean);
                    }
                    view.getCasesSucced(casesBeans);
                } else {
//                    view.showToastMessage(response.getMsg());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.getCasesFail();
            }
        });
    }
}
